package com.yiwu.netty.util;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;

/**
 * @version 1.0
 * @description TODO
 * @date 2024/6/19 18:52
 */
public class RocketMQProducerSingleton {
    private static final DefaultMQProducer defaultMQProducer;

    static {
        defaultMQProducer = new DefaultMQProducer("message_system_producer");
        defaultMQProducer.setNamesrvAddr("http://118.178.229.137:9876");
        try {
            defaultMQProducer.start();
        } catch (MQClientException e) {
            e.printStackTrace();
        }
    }

    public static DefaultMQProducer getProducer() {
        return defaultMQProducer;
    }

    // 在应用程序关闭时调用
    public static void shutdown() {
        defaultMQProducer.shutdown();
    }

}
